from pydantic import BaseModel, Field
from typing import List, Optional


class BaseExam(BaseModel):
    title: Optional[str] = Field("", description="标题")
    cover: Optional[str] = Field("", description="封面")
    desc: Optional[str] = Field("", description="备注")
    state: Optional[bool] = True
    questions: Optional[list] = Field("", description="答案")

class ExamCreate(BaseExam):
    ...


class ExamUpdate(BaseExam):
    id: int

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseQuestion(BaseModel):
    exam_id: Optional[int] = Field(0, description="试卷id")
    question: Optional[str] = Field("", description="问题")
    selects: Optional[list] = Field(None, description="选项")
    answer: Optional[list] = Field("", description="答案")


class QuestionCreate(BaseQuestion):
    ...


class QuestionUpdate(BaseQuestion):
    id: int

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseResult(BaseModel):
    exam_id: Optional[int] = Field(0, description="试卷id")
    name: Optional[str] = Field("", description="名称")
    rate: Optional[str] = Field("", description="比例")
    score_min: Optional[int] = Field(0, description="分数区间最小值")
    score_max: Optional[int] = Field(100, description="分数区间最大值")
    url_type: Optional[int] = Field(0, description="跳转类型")
    url: Optional[str] = Field("", description="跳转地址")
    picture: Optional[list] = Field(None, description="用户答案")


class ResultCreate(BaseResult):
    ...


class ResultUpdate(BaseResult):
    id: int

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseUserAnswer(BaseModel):
    user_id: Optional[int] = Field(0, description="用户id")
    exam_id: Optional[int] = Field(0, description="试卷id")
    user_answer: Optional[list] = Field(None, description="用户答案")
    user_score: Optional[int] = Field(0, description="用户得分")
    result_name: Optional[str] = Field("", description="结果名称")


class UserAnswerPost(BaseModel):
    user_id: Optional[int] = Field(0, description="用户id")
    exam_id: Optional[int] = Field(0, description="试卷id")
    user_answer: Optional[list] = Field(None, description="用户答案")

class UserAnswerCreate(BaseUserAnswer):
    ...

class UserAnswerUpdate(BaseUserAnswer):
    id: int

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})
